import extend from 'dva-model-extend';
import settings from '@/settings';
import model from '@/baseModel';
import { getOne, getList, check, deleteRows } from '@/services/auth';

const { pagination } = settings;
const initState = {

}

export default extend(model, {
  namespace: '$auth',
  state: {
    ...initState
  },
  effects: {
    *reset(_, { put }) {
      yield put({
        type: 'updateState',
        payload: {
          data: undefined
        },
      });
    },
    *fetchOne({ payload }, { call, put }) {
      const { data = {} } = yield call(getOne, payload);
      yield put({
        type: 'updateState',
        payload: {
          data
        },
      });
    },
    *fetchList({ payload = pagination }, { call, put }) {
      const { data } = yield call(getList, payload);
      yield put({
        type: 'updateState',
        payload: {
          list: data,
          params: payload,
        },
      });
    },
    *delete({ payload }, { call }) {
      yield call(deleteRows, payload);
    },
    *valid({ payload }, { call }) {
      yield call(check, payload);
    },
  },
});
